<template>
	<div>
		<div class="personal layout-pd">
			<el-row>
				<el-col>
					<el-card class="mb15" shadow="hover">
						<span class="welcome">欢迎进入万代卡玩卡片机活动申请平台</span>
					</el-card>
				</el-col>
				<!-- 列表 -->
				<el-col :xs="24" :sm="12" class="personal-info">
					<el-card shadow="hover">
						<template #header>
							<span>最新消息</span>
							<!-- <a @click="router.push({path:'/activity/all'})" class="personal-info-more">更多</a> -->
						</template>
						<div class="personal-info-box">
							<ul class="personal-info-ul">
								<li v-for="(v, k) in newsAllList" :key="k" class="personal-info-li">
									<a class="personal-info-li-title" @click="toNewsDetail(v)" :key="v.id">{{ v.title }}</a>
								</li>
							</ul>
						</div>

						<div class="pagination-block">
							<el-pagination :hide-on-single-page="isSinglePage" v-model:current-page="newsCurrentPage"
								v-model:page-size="newsPageSize" :small="small" :disabled="disabled" :background="background"
								layout="prev, pager, next, jumper" :total="newsTotalPage" @size-change="handleSizeChange"
								@current-change="handleCurrentChange" />
						</div>
					</el-card>
				</el-col>
				<el-col :xs="24" :sm="12" class="pl15 personal-info">
					<el-card shadow="hover">
						<div class="swiper-title">热门资讯</div>
						<div class="swiper-con">
							<swiper :autoplay="{ delay: 4000, disableOnInteraction: false }" :loop="true" :modules="modules"
								@swiper="onSwiper" :navigation="navigate" @slideChange="onSlideChange">
								<swiper-slide v-for="item in newsList" @click="toNewsDetail(item)" :key="item.id">
									<!-- <img :src="item.pic" alt=""> -->
									<img :src="item.pic" alt="">
									<div class="slide-title">{{ item.title }}</div>
								</swiper-slide>
								<div class="swiper-button-prev" slot="button-prev"></div>
								<div class="swiper-button-next" slot="button-next"></div>
							</swiper>
						</div>
					</el-card>
				</el-col>
				<!-- 个人信息 -->
				<el-col :xs="24" :sm="12" class="personal-info">
					<el-card shadow="hover">
						<template #header>
							<span>最新活动</span>
							<a @click="router.push({ path: '/activity/all' })" class="personal-info-more">更多</a>
						</template>
						<div class="personal-info-box">
							<ul class="personal-info-ul">
								<li v-for="(v, k) in activityList" :key="k" class="personal-info-li">
									<a class="personal-info-li-title" @click="toActivity(v)">{{ v.title }}</a>
								</li>
							</ul>
						</div>
					</el-card>
				</el-col>
				<el-col :xs="24" :sm="12" class="pl15 personal-info">
					<el-card shadow="hover">
						<template #header>
							<span>最新物料</span>
							<a @click="router.push({ path: '/material' })" class="personal-info-more">更多</a>
						</template>
						<div class="personal-info-box">
							<ul class="personal-info-ul">
								<li v-for="(v, k) in materialList" :key="k" class="personal-info-li">
									<a class="personal-info-li-title" @click="toMaterialDetail(v)">{{ v.title }}</a>
								</li>
							</ul>
						</div>
					</el-card>
				</el-col>
			</el-row>
		</div>
		<div class="my-detail" v-if="showChild!=''">

			<div class="my-detail-con">
				<div class="my-detail-close" @click="showChild = ''">
					<ele-Close />
				</div>
				<newsDetail :data="childData" v-if="showChild==='newsdetail'"></newsDetail>
				<materialDetail :data="childData" v-if="showChild==='materialdetail'"></materialDetail>
			</div>

		</div>
	</div>

</template>

<script setup lang="ts" name="personal">
import router from '/@/router/index';
import { ref } from 'vue';
import { useIndexApi } from '/@/api/index';
import newsDetail from '/@/components/atmNewsDetail/index.vue'
import materialDetail from '/@/components/atmMaterialDetail/index.vue'

const newsCurrentPage = ref(1)
const newsPageSize = ref(5)
const small = ref(false)
const background = ref(false)
const newsTotalPage = ref(1);
// const isSinglePage = computed(() => {
// 	return newsTotalPage.value<=1
// })
const isSinglePage = ref(false)
const disabled = ref(false)
const handleSizeChange = (val: number) => {
	console.log(`${val} items per page`)
}
const handleCurrentChange = (val: number) => {
	console.log(`current page: ${val}`)
}

import { useActivityApi } from '/@/api/activity';
const activityList = ref([]);
async function getActivity() {
	const res = await useActivityApi().actList({
		pageNo: 1,
		pageSize: 10,
		gameId: 0,
		status: 0,
	});
	if (res) {
		activityList.value = [...res.data.list];
	}

}
getActivity()


const newsList = ref([])
async function getNews() {
	const res = await useIndexApi().getNews({
		"pageSize": 5,
		"pageNo": 1,
		"isGood": 1
	});
	newsList.value = [...res.data.list];
}
getNews()

const newsAllList = ref([])
async function getAllNews() {
	const res = await useIndexApi().getNews({
		"pageSize": newsPageSize.value,
		"pageNo": newsCurrentPage.value,
	});
	newsTotalPage.value = res.data.total
	newsAllList.value = [...res.data.list];
}
getAllNews()


import { Swiper, SwiperSlide, } from 'swiper/vue';

import { Autoplay, Navigation } from 'swiper/modules';
import 'swiper/css';
import 'swiper/css/navigation';

const modules = [Autoplay, Navigation];

const navigate = {
	nextEl: '.swiper-button-next',
	prevEl: '.swiper-button-prev',
};
const onSwiper = () => {
};
const onSlideChange = () => {
};

function toActivity(data) {
	router.push({ path: '/activity/all/detail', query: { id: data.id } })
}

const childData = ref({});
const showChild = ref('')
function toNewsDetail(data) {
	childData.value = data;
	showChild.value = 'newsdetail';
}
function toMaterialDetail(data) {
	childData.value = data;
	showChild.value = 'materialdetail';
}
const materialList = ref([])
async function getMaterial() {
	const res = await useIndexApi().getMaterial({
		"pageSize": 5,
		"pageNo": 1,
	});
	materialList.value = [...res.data.list];
}
getMaterial()

</script>

<style scoped lang="scss">
@import '../../theme/mixins/index.scss';

.personal {
	.personal-user {
		height: 130px;
		display: flex;
		align-items: center;

		.personal-user-left {
			width: 100px;
			height: 130px;
			border-radius: 3px;

			:deep(.el-upload) {
				height: 100%;
			}

			.personal-user-left-upload {
				img {
					width: 100%;
					height: 100%;
					border-radius: 3px;
				}

				&:hover {
					img {
						animation: logoAnimation 0.3s ease-in-out;
					}
				}
			}
		}

		.personal-user-right {
			flex: 1;
			padding: 0 15px;

			.personal-title {
				font-size: 18px;
				@include text-ellipsis(1);
			}

			.personal-item {
				display: flex;
				align-items: center;
				font-size: 13px;

				.personal-item-label {
					color: var(--el-text-color-secondary);
					@include text-ellipsis(1);
				}

				.personal-item-value {
					@include text-ellipsis(1);
				}
			}
		}
	}

	.personal-info {
		margin-bottom: 20px;

		.personal-info-more {
			float: right;
			color: var(--el-text-color-secondary);
			font-size: 13px;

			&:hover {
				color: var(--el-color-primary);
				cursor: pointer;
			}
		}

		.personal-info-box {
			height: 130px;
			overflow: hidden;

			.personal-info-ul {
				list-style: none;

				.personal-info-li {
					font-size: 13px;
					padding-bottom: 10px;

					.personal-info-li-title {
						display: inline-block;
						@include text-ellipsis(1);
						color: var(--el-text-color-secondary);
						text-decoration: none;
					}

					& a:hover {
						color: var(--el-color-primary);
						cursor: pointer;
					}
				}
			}
		}
	}

	.personal-recommend-row {
		.personal-recommend-col {
			.personal-recommend {
				position: relative;
				height: 100px;
				border-radius: 3px;
				overflow: hidden;
				cursor: pointer;

				&:hover {
					i {
						right: 0px !important;
						bottom: 0px !important;
						transition: all ease 0.3s;
					}
				}

				i {
					position: absolute;
					right: -10px;
					bottom: -10px;
					font-size: 70px;
					transform: rotate(-30deg);
					transition: all ease 0.3s;
				}

				.personal-recommend-auto {
					padding: 15px;
					position: absolute;
					left: 0;
					top: 5%;
					color: var(--next-color-white);

					.personal-recommend-msg {
						font-size: 12px;
						margin-top: 10px;
					}
				}
			}
		}
	}

	.personal-edit {
		.personal-edit-title {
			position: relative;
			padding-left: 10px;
			color: var(--el-text-color-regular);

			&::after {
				content: '';
				width: 2px;
				height: 10px;
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				background: var(--el-color-primary);
			}
		}

		.personal-edit-safe-box {
			border-bottom: 1px solid var(--el-border-color-light, #ebeef5);
			padding: 15px 0;

			.personal-edit-safe-item {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.personal-edit-safe-item-left {
					flex: 1;
					overflow: hidden;

					.personal-edit-safe-item-left-label {
						color: var(--el-text-color-regular);
						margin-bottom: 5px;
					}

					.personal-edit-safe-item-left-value {
						color: var(--el-text-color-secondary);
						@include text-ellipsis(1);
						margin-right: 15px;
					}
				}
			}

			&:last-of-type {
				padding-bottom: 0;
				border-bottom: none;
			}
		}
	}
}

.welcome {
	color: #3691ff;
	font-size: 24px;
}

.swiper-title {
	height: 50px;
	line-height: 30px;
	text-align: center;
	color: #3691ff;
	font-size: 24px;
}

.swiper-con {
	width: 100%;
	height: 200px;
	margin: 0 auto;
	overflow: hidden;

	img {
		width: auto;
		height: 150px;
		display: block;
		margin: auto;
	}

	.slide-title {
		height: 50px;
		line-height: 50px;
		text-align: center;
		color: rgb(54, 145, 255);
		font-size: 18px;
	}

	.swiper {
		height: 100%;
		width: 100%;
	}

}

.my-detail {
	width: 100%;
	height: 100%;
	position: fixed;
	left: 0;
	top: 0;
	z-index: 10;
	background: rgba(0, 0, 0, 0.6);

	.my-detail-close {
		width: 30px;
		height: 30px;
		position: absolute;
		right: 5px;
		top: 5px;
		cursor: pointer;
		z-index: 2;
	}

	.my-detail-con {
		width: 95%;
		max-width: 800px;
		height: 600px;
		height: 90%;
		max-height: 600px;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		margin: auto;
		z-index: 2;
	}
}
</style>
